package com.party.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import com.party.domain.Mold;
/*
 * 
 * @author Caizhf
 * @date 2017年6月4日下午4:32:35
 * @version v.0.1
 * @email 1115054416@qq.com 
 *
 * <p>Description: 二级服务分类</p>
 *
 */
public interface MoldMapper {
	
	@Insert("INSERT INTO mold(mold_name) VALUES(#{mold_name})")
	@SelectKey(before=false,keyProperty="mid",resultType=Integer.class, statement = { "SELECT LAST_INSERT_ID()" })
	int insert(Mold mold);
	
	@Select("SELECT * FROM mid WHERE mid=#{mid}")
	Mold findById(int mid);
	
	@Select("SELECT * FROM mold")
	List<Mold> findAll();
	
	@Update("UPDATE mold SET mold_name=#{mold_name}")
	int update(Mold mold);
	
	@Delete("DELETE FROM mold WHERE id=#{mid}")
	int deleteById(int mid);
	
	/**
	 * 根据产品类型查找相应的分类
	 * @param product_type
	 * @return
	 */
	@Select("SELECT m.mold_name FROM"
			+ " mold m JOIN services s ON m.mid=s.mold_id"
			+ " JOIN product p ON p.pid=s.product_id"
			+ " WHERE p.product_type=#{product_type}")
	List<String> findAllByProductType(String product_type);

	@Select("SELECT * FROM mold m WHERE m.mold_name=#{mold_name}")
	Mold findByName(String mold_name);
	
}